package studio.xiaoyun.core;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextClosedEvent;
import org.springframework.stereotype.Component;

/**
 * 系统停止时执行一些操作
 */
@Component
public class SystemStop implements ApplicationListener<ContextClosedEvent> {
    private Logger log = LoggerFactory.getLogger(SystemStop.class);
    private static boolean isStop = false;

    @Override
    public void onApplicationEvent(ContextClosedEvent event) {
        if(!isStop){   //防止执行多次
            log.warn("系统已停止");
            isStop = true;
        }
    }

}
